import React, { Component, lazy, Suspense } from "react";
import { Link, Switch, Route } from "react-router-dom";

// import Home from "./Home";
// import About from "./About";

const Home = lazy(() => import("./Home"));
const About = lazy(() => import("./About"));

class App extends Component {
  render() {
    return (
      <>
        <h3>路由懒加载</h3>
        <ul>
          <li>
            <Link to="/home">home</Link>
          </li>
          <li>
            <Link to="/about">about</Link>
          </li>
        </ul>

        <hr />

        {/* <Suspense fallback={<div>loading...</div>}> */}
        <Switch>
          <Route path="/home">
            <Suspense fallback={<div>loading...</div>}>
              <Home />
            </Suspense>
          </Route>
          <Route path="/about">
            <Suspense fallback={<div>loading...</div>}>
              <About />
            </Suspense>
          </Route>
        </Switch>
        {/* </Suspense> */}
      </>
    );
  }
}

export default App;
